package cn.xfdzx.android.apps.shop.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.activity.XFDShopDetailsActivity;
import cn.xfdzx.android.apps.shop.bean.MyFocusShopBean;
import cn.xfdzx.android.apps.shop.bean.OrderProcessBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.presenter.MyFocusShopPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.util.Utils;

/**
 * Creator: zf.
 * Date: 2020/7/20.
 * Description:我的关注零售店铺.
 */
public class MyFocusShop_RetailAdapter extends RecyclerView.Adapter<MyFocusShop_RetailAdapter.MyViewHolder> {

    private ItemClickListener mItemClickListener;
    private List<MyFocusShopBean.DataBean.RetailBean> mList;
    private Activity mContext;
    private MyFocusShopPresenter mPresenter;

    public MyFocusShop_RetailAdapter(Activity context, List<MyFocusShopBean.DataBean.RetailBean> list,
                                     MyFocusShopPresenter mPresenter) {
        this.mList = list;
        this.mContext = context;
        this.mPresenter = mPresenter;
    }

    @NonNull
    @Override
    public MyFocusShop_RetailAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_focusshop_retail, parent, false);
        MyFocusShop_RetailAdapter.MyViewHolder myHolder = new MyFocusShop_RetailAdapter.MyViewHolder(inflate);

        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyFocusShop_RetailAdapter.MyViewHolder holder, final int position) {

        if (EmptyUtil.isNotEmpty(mList.get(position).getOffline_shop_name())){
            holder.tv_shop_name.setText(mList.get(position).getOffline_shop_name());
        }else {
            holder.tv_shop_name.setText(mList.get(position).getName());
        }

        holder.tv_shop_level.setText(mList.get(position).getStar());
        holder.tv_shop_month_sales.setText("月销"+mList.get(position).getMonthly_sales());
        holder.tv_home_shop_list_up_send.setText("起送¥"+mList.get(position).getSend_fees());
        holder.tv_home_shop_list_basis.setText("基础运费¥"+mList.get(position).getBase_freight());
        ImageGlideUtil.loadImage(mContext,holder.iv_home_shop_list,mList.get(position).getLogo());
        if (EmptyUtil.isNotEmpty(mList.get(position).getExpress_name())){
            holder.tv_zuansong.setText(mList.get(position).getExpress_name());
        }else{
            holder.tv_zuansong.setText("");
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Utils.isFastClick()) {
                    //mItemClickListener.onItemClick(position);
                    Intent intent = new Intent(mContext, ShopActivity.class);
                    intent.putExtra("shop_id",mList.get(position).getSid()+"");
                    mContext.startActivity(intent);
                }
            }
        });

        holder.tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    mPresenter.getCancleFocus(mList.get(position).getSid()+"");
                }
            }
        });

        holder.tv_open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    mItemClickListener.onItemClick(position);
                }
            }
        });

    }

    public void setDate(List<MyFocusShopBean.DataBean.RetailBean> list){
        this.mList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.iv_home_shop_list)
        ImageView iv_home_shop_list;
        @BindView(R.id.tv_shop_name)
        TextView tv_shop_name;
        @BindView(R.id.tv_shop_level)
        TextView tv_shop_level;
        @BindView(R.id.tv_shop_month_sales)
        TextView tv_shop_month_sales;
        @BindView(R.id.tv_home_shop_list_up_send)
        TextView tv_home_shop_list_up_send;
        @BindView(R.id.tv_home_shop_list_basis)
        TextView tv_home_shop_list_basis;
        @BindView(R.id.tv_delete)
        TextView tvDelete;
        @BindView(R.id.tv_open)
        ImageView tv_open;
        @BindView(R.id.tv_zuansong)
        TextView tv_zuansong;



        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }

    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}

